from pygame import display as pdis
from addon.PSO.pso import PSO
from lib.res.lang import CH
from lib.ZLabel import ZLabel
from lib.ZLayout import ZLayout
from lib.res.fun import _get_center , _cutImg , _create_image_alpha , _change_size , _create_font
from lib.res.glo import COLOR , SRC , default_font
from resource.script.Skill.lib.Skill import Skill
from resource.ui.btns import _BtnStart_ , _BtnExit_COPY_ , _BtnExit_ , _BtnBackpack_
from resource.ui.sprites import PlayerImage


class MainMenu ( ZLayout ) :
	def __init__ ( self , father = pdis.get_surface ( ) ) :
		super ( MainMenu , self ).__init__ ( father , [ 0 , 0 , 85 , 100 ] )
		self._pos = _get_center ( self.rect )
		self._add ( _BtnStart_ ( self ) , _BtnExit_COPY_ ( self ) )


class GameMenu ( ZLayout ) :
	def __init__ ( self , father = pdis.get_surface ( ) ) :
		super ( GameMenu , self ).__init__ ( father , [ 0 , 0 , 85 , 100 ] )
		self._pos = _get_center ( self.rect )
		self.children.append ( _BtnExit_ ( self ) )


class PanelData ( ZLayout ) :
	def __init__ ( self , father , players ) :
		super ( PanelData , self ).__init__ ( father , rect = [ 0 , 0 , 250 , 400 ] )
		self._pos = 600 , 100
		self.players = players
		self._add ( PSO ( self ,
		                  SRC [ 'image' ] [ 'pso' ] [ 0 ] ,
		                  pos = [ 69 , 63 ] ,
		                  speed_x = [ -4 , 1 ] ,
		                  speed_y = [ -3 , 1 ] ,
		                  max = 20 ,
		                  life = .4 ) ,
		            PSO ( self ,
		                  SRC [ 'image' ] [ 'pso' ] [ 0 ] ,
		                  pos = [ -8 , 63 ] ,
		                  speed_x = [ -1 , 4 ] ,
		                  speed_y = [ -3 , 1 ] ,
		                  max = 20 ,
		                  life = .4 ) )
		self._add ( PlayerImage ( self , players [ 0 ].icon_big ) )
		self._add ( ZLabel ( self ,
		                     text = CH [ 'name' ] + players [ 0 ].name ,
		                     pos = [ 20 , 85 ] ,
		                     color = COLOR [ 'font' ] [ 'color' ] [ 1 ] ,
		                     shadow = COLOR [ 'font' ] [ 'shadow' ] [ 0 ] ) )
		self._add ( ZLabel ( self ,
		                     text = CH [ 'hp' ] + str ( players [ 0 ].hp ) ,
		                     pos = [ 0 , 110 ] ,
		                     color = COLOR [ 'font' ] [ 'color' ] [ 1 ] ,
		                     shadow = COLOR [ 'font' ] [ 'shadow' ] [ 0 ] ) )
		self._add ( ZLabel ( self ,
		                     text = CH [ 'js' ] + str ( players [ 0 ].js ) ,
		                     pos = [ 0 , 130 ] ,
		                     color = COLOR [ 'font' ] [ 'color' ] [ 1 ] ,
		                     shadow = COLOR [ 'font' ] [ 'shadow' ] [ 0 ] ) )
		self._add ( ZLabel ( self ,
		                     text = CH [ 'mp' ] + str ( players [ 0 ].mp ) ,
		                     pos = [ 0 , 150 ] ,
		                     color = COLOR [ 'font' ] [ 'color' ] [ 1 ] ,
		                     shadow = COLOR [ 'font' ] [ 'shadow' ] [ 0 ] ) )
		self._add ( ZLabel ( self ,
		                     text = CH [ 'ad' ] + str ( players [ 0 ].ad ) ,
		                     pos = [ 0 , 170 ] ,
		                     color = COLOR [ 'font' ] [ 'color' ] [ 1 ] ,
		                     shadow = COLOR [ 'font' ] [ 'shadow' ] [ 0 ] ) )
		self._add ( ZLabel ( self ,
		                     text = CH [ 'dd' ] + str ( players [ 0 ].dd ) ,
		                     pos = [ 0 , 190 ] ,
		                     color = COLOR [ 'font' ] [ 'color' ] [ 1 ] ,
		                     shadow = COLOR [ 'font' ] [ 'shadow' ] [ 0 ] ) )
		images = _cutImg ( _create_image_alpha ( "assets/image/item/7.png" ) )
		img_key = images [ 163 ]
		self.img_key = _change_size ( img_key , [ 20 , 20 ] )
		self.X = _create_font ( "X" , COLOR [ 'font' ] [ 'color' ] [ 1 ] , default_font )
		self._add ( ZLabel ( self ,
		                     text = str ( players [ 0 ]._have_item ( 1 ) ) ,
		                     pos = [ 38 , 218 ] ,
		                     color = COLOR [ 'font' ] [ 'color' ] [ 1 ] ,
		                     shadow = COLOR [ 'font' ] [ 'shadow' ] [ 0 ] ) )
		for key , s in enumerate ( self.players [ 0 ].skill ) :
			s = Skill ( self , int ( self.players [ 0 ].skill [ key ] ) )
			s._pos = 0 , 250 + key * 45
			self._add ( s ) ,
		self._add ( _BtnBackpack_ ( self ) )

	def draw ( self ) :
		super ( PanelData , self ).draw ( )
		self.children [ 3 ].draw ( text = self.players [ 0 ].name )
		self.children [ 4 ].draw ( text = CH [ 'hp' ] + str ( self.players [ 0 ].hp ) )
		self.children [ 5 ].draw ( text = CH [ 'js' ] + str ( self.players [ 0 ].js ) )
		self.children [ 6 ].draw ( text = CH [ 'mp' ] + str ( self.players [ 0 ].mp ) )
		self.children [ 7 ].draw ( text = CH [ 'ad' ] + str ( self.players [ 0 ].ad ) )
		self.children [ 8 ].draw ( text = CH [ 'dd' ] + str ( self.players [ 0 ].dd ) )
		self.children [ 9 ].draw ( text = str ( self.players [ 0 ]._have_item ( 1 ) ) )
		self.screen.blit ( self.img_key , [ self._pos [ 0 ] , self._pos [ 1 ] + 220 ] )
		self.screen.blit ( self.X , [ self._pos [ 0 ] + 25 , self._pos [ 1 ] + 218 ] )

	def update ( self , event , pos , key ) :
		super ( PanelData , self ).update ( event , pos , key )
